package main1.e_Model;

import main.e_FactoryModel.FactoryDiv;
import main.e_FactoryModel.IFactory;
import main.e_FactoryModel.Operation;
import main.e_FactoryModel.OperationFactory;

/**
 * Created by newtranx_011 on 2017/9/13.
 */
public class Main {

    public static void main(String[] args) {
//        impleFactory();
        factory();
    }

    public static void factory(){
        String strA = "12";
        String strB = "5";
        double numA = Double.parseDouble(strA);
        double numB = Double.parseDouble(strB);
        IFactory iFactory = new FactoryDiv();
        Operation operation = iFactory.CreateOperation();
//        Operation operation =  OperationFactory.createOperation("/");
        operation.setNumA(numA);
        operation.setNumB(numB);
        double result = 0d;
        try {
            result = operation.getResult();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        System.out.println(result);
    }

    /**
     * 简单工厂的调用
     */
    public static void impleFactory(){
        String strA = "12";
        String strB = "5";
        double numA = Double.parseDouble(strA);
        double numB = Double.parseDouble(strB);
        Operation operation =  OperationFactory.createOperation("/");
        operation.setNumA(numA);
        operation.setNumB(numB);
        double result = 0d;
        try {
            result = operation.getResult();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        System.out.println(result);
    }
}
